package com.bayss.core.util;

import com.bayss.core.enums.OrderType;
import org.apache.commons.lang.StringUtils;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class OrderUtils {

    private OrderUtils(){
    }

    public static String getOrderNo(OrderType orderType, Long uid, String time, boolean isParent) {
        if (StringUtils.isBlank(time)) {
            time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        }
        String orderNo = orderType.ordinal() + time + uid;
        if (isParent) {
            orderNo = "x" + orderNo;
        }
        return orderNo;
    }

    public static String getRecvNo(){
        Random r = new Random(1);
        int ran1 = r.nextInt(999999);
        return ran1+"";
    }


    public static String getActiveNo(Long uid) {
        return "at" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + uid;
    }

    public static String getRechargeNo(Long uid) {
        return "rc" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + uid;
    }

    public static double costM (double latitude, double longitude, double targetLatitude, double targetLongitude){
        GlobalCoordinates source = new GlobalCoordinates(latitude, longitude);
        GlobalCoordinates target = new GlobalCoordinates(targetLatitude, targetLongitude);
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target);
        return geoCurve.getEllipsoidalDistance();
    }
}
